#include "glprogressbar.h"

#ifdef WIN32
	#include <Windows.h>
#endif

#include <GL/gl.h>

GlProgressBar::GlProgressBar()
: m_Width(0.f)
, m_Height(0.f)
, m_Progress(0.f)
{
}

GlProgressBar::GlProgressBar(float width, float height, float progress)
: m_Width(width)
, m_Height(height)
, m_Progress(progress)
{
}


GlProgressBar::~GlProgressBar()
{
}

void GlProgressBar::setProgress(float progress)
{
    m_Progress = progress;
}

void GlProgressBar::setDimensions(float width, float height)
{
    m_Width = width;
    m_Height = height;
}

void GlProgressBar::render()
{
    glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_MODE);
        
    // progressbar
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    glBegin(GL_QUADS);
        glColor4f(1.f, 1.f, 1.f, 1.f);
        glVertex2f(0.f, 0.f);
        glVertex2f(m_Width * m_Progress, 0.f);
        glColor4f(.8f, .8f, .8f, 1.f);
        glVertex2f(m_Width * m_Progress, m_Height);
        glVertex2f(0.f, m_Height);
    glEnd();
    
    // progressbar outline
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glBegin(GL_QUADS);
        glVertex2f(0.f, 0.f);
        glVertex2f(m_Width, 0.f);
        glVertex2f(m_Width, m_Height);
        glVertex2f(0.f, m_Height);
    glEnd();
    
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    
    glPopAttrib();
}
